#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import models

# Create your models here.
from dvadmin.utils.models import CoreModel


class VehicleInfoModel(CoreModel):
    vin = models.CharField(max_length=255, unique=True, verbose_name="vin")
    vehicle_type = models.IntegerField("车辆类型")
    vehicle_fence = models.CharField("电子围栏", max_length=60, default='', blank=True)
    vehicle_status = models.IntegerField("车辆在线状态")
    vehicle_motor = models.CharField("电机厂商", max_length=128)
    vehicle_battery = models.CharField("电池厂商", max_length=128)
    vehicle_motor_code = models.CharField("电机编号", max_length=128, default='', blank=True)
    vehicle_battery_code = models.CharField("电池编号", max_length=128, default='', blank=True)
    start_point = models.CharField("启点", max_length=60, default='', blank=True)
    end_point = models.CharField("终点", max_length=60, default='', blank=True)
    distance = models.IntegerField("启点-终点距离", default=0)

    class Meta:
        db_table = "vehicle_info"
        verbose_name = '车辆表'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)


class VehicleFaultInfoModel(CoreModel):
    fault_type = models.CharField('故障类型', max_length=60)
    fault_group = models.CharField('故障组', max_length=60)
    fault_site = models.CharField('故障位', max_length=60)
    fault_value = models.CharField('故障值', max_length=60)
    fault_label = models.CharField('故障标签', max_length=60)
    fault_code = models.CharField('故障码', max_length=60)
    is_warn = models.IntegerField('是否警告', default=0)

    class Meta:
        db_table = "vehicle_fault_info"
        verbose_name = '故障信息表'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)


class VehicleFaultLogModel(CoreModel):
    vin = models.CharField(max_length=255, verbose_name="vin")
    fault_code = models.CharField('故障码', max_length=60)
    log_status = models.CharField('报警状态', max_length=60, default="")
    start_time = models.DateTimeField('开始报警时间', auto_now_add=True)
    end_time = models.DateTimeField('开始报警时间')
    process_by = models.CharField('处理人', max_length=60, default="")
    process_time = models.DateTimeField('处理时间', null=True, default=None)

    class Meta:
        db_table = "vehicle_fault_log"
        verbose_name = '故障报警记录表'
        verbose_name_plural = verbose_name
        ordering = ('-start_time',)


class VehicleFenceModel(CoreModel):
    fence_name = models.CharField('围栏名称', max_length=60)
    fence_alarm_type = models.CharField('围栏类型', max_length=60)
    status = models.IntegerField("启用状态", default=0)
    path = models.CharField('围栏地址', max_length=2048, default="")

    class Meta:
        db_table = "vehicle_fence"
        verbose_name = '电子围栏表'
        verbose_name_plural = verbose_name


class VehicleMoveInfoModel(CoreModel):
    id = models.CharField(max_length=128, primary_key=True)
    vehicle_vin = models.CharField(max_length=255, verbose_name="vin")
    start_time = models.DateTimeField('开始行程时间', auto_now_add=True)
    end_time = models.DateTimeField('结束行程时间', null=True, blank=True)
    score = models.IntegerField("驾驶得分", default=0)
    offset = models.CharField('偏移程度', max_length=255, default="")

    class Meta:
        db_table = "vehicle_move_info"
        verbose_name = '车辆运行记录表'
        verbose_name_plural = verbose_name
        ordering = ('-start_time',)
